#!/bin/bash
#设定防火墙和selinux

#路径

DISTRO=`./01_Get_Dist_Name Get_Dist_Name`

version=`cat /etc/redhat-release |awk '{print substr($4,1,1)}'`

close_selinux_perman(){
	#修改selinux配置文件 /etc/selinux/config
	sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config
	if [ $? -eq 0 ];then
		echo "成功设置开机不自启动selinux"
	else
		echo "初始化selinux失败"
	fi
}       

#防火墙 开 空规则
init_iptables(){
	if [ $DISTRO == "CentOS" -a ${version} == "7" ];then
		systemctl stop firewalld.service
		systemctl disable firewalld.service
		systemctl enable iptables
		systemctl start iptables
		#删除指定表中用户自定义的规则链
		iptables -X
		#清空（FLUSH）
		iptables -F
		#将所有表的所有链的字节和数据包计数器清零
		iptables -Z
		#保存规则
		service iptables save
		if [ $? -eq 0 ];then
			echo "CentOS7 成功初始化防火墙"
		else
			echo "CentOS7 初始化防火墙失败"
		fi
		#iptables-save > /etv/sysconfig/iptables
	elif [ $DISTRO == "CentOS" -a ${version} == "6" ];then
		service iptables start
		iptables -P INPUT ACCEPT
		iptables -F
		iptables -X
		iptables -Z
		service iptables save
		if [ $? -eq 0 ];then
                	echo "CentOS6 成功初始化防火墙"
                else
                        echo "CentOS6 初始化防火墙失败"
                fi

	else
		iptables -F
		iptables -X
		iptables -Z
		if [ $? -eq 0 ];then
                        echo "Ubuntu14 成功初始化防火墙"
                else
                        echo "Ubuntu14 初始化防火墙失败"
                fi

	fi
}
close_selinux_perman
init_iptables
